package com.pms.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.pms.system.domain.vo.PmsCheckinInfoVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pms.common.annotation.Log;
import com.pms.common.core.controller.BaseController;
import com.pms.common.core.domain.AjaxResult;
import com.pms.common.enums.BusinessType;
import com.pms.system.domain.PmsCheckinInfo;
import com.pms.system.service.IPmsCheckinInfoService;
import com.pms.common.utils.poi.ExcelUtil;
import com.pms.common.core.page.TableDataInfo;

/**
 * 入住信息Controller
 * 
 * @author 达瓦里氏
 * @date 2023-03-04
 */
@RestController
@RequestMapping("/system/PmsCheckinInfo")
public class PmsCheckinInfoController extends BaseController
{
    @Autowired
    private IPmsCheckinInfoService pmsCheckinInfoService;

    /**
     * 查询入住信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsCheckinInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsCheckinInfo pmsCheckinInfo)
    {
        startPage();
        List<PmsCheckinInfoVo> list = pmsCheckinInfoService.selectPmsCheckinInfoList(pmsCheckinInfo);
        return getDataTable(list);
    }

    /**
     * 导出入住信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsCheckinInfo:export')")
//    @Log(title = "入住信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsCheckinInfo pmsCheckinInfo)
    {
        List<PmsCheckinInfoVo> list = pmsCheckinInfoService.selectPmsCheckinInfoList(pmsCheckinInfo);
        ExcelUtil<PmsCheckinInfoVo> util = new ExcelUtil<PmsCheckinInfoVo>(PmsCheckinInfoVo.class);
        util.exportExcel(response, list, "入住信息数据");
    }

    /**
     * 获取入住信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsCheckinInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pmsCheckinInfoService.selectPmsCheckinInfoById(id));
    }

    /**
     * 新增入住信息（用户端）
     */
    @PostMapping(value = "/addUser")
    public AjaxResult getInfo(@RequestBody PmsCheckinInfoVo pmsCheckinInfoVo)
    {
        int add = -1;
        try{
            add = pmsCheckinInfoService.insertPmsCheckinByUser(pmsCheckinInfoVo);
        } catch (Exception e){
            throw new RuntimeException("新增失败,系统异常");
        }
        return toAjax(add);
    }


    /**
     * 新增入住信息
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsCheckinInfo:add')")
//    @Log(title = "入住信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsCheckinInfo pmsCheckinInfo)
    {
        int add = -1;
        try{
           add = pmsCheckinInfoService.insertPmsCheckinInfo(pmsCheckinInfo);
        } catch (Exception e){
                throw new RuntimeException("新增失败,系统异常");
            }
        return toAjax(add);
    }

    /**
     * 修改入住信息
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsCheckinInfo:edit')")
//    @Log(title = "入住信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsCheckinInfo pmsCheckinInfo)
    {
        return toAjax(pmsCheckinInfoService.updatePmsCheckinInfo(pmsCheckinInfo));
    }

    /**
     * 删除入住信息
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsCheckinInfo:remove')")
//    @Log(title = "入住信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsCheckinInfoService.deletePmsCheckinInfoByIds(ids));
    }


    /**
     * 办理入住
     */
    @GetMapping(value = "/checkInByUserCode/{id}")
    public AjaxResult checkInByUserCode(@PathVariable("id") Long id)
    {
        return toAjax(pmsCheckinInfoService.checkInByUserCode(id));
    }


    /**
     * 退房
     */
    @GetMapping(value = "/CheckOut/{id}")
    public AjaxResult CheckOut(@PathVariable("id") Long id)
    {
        return toAjax(pmsCheckinInfoService.CheckOut(id));
    }
}
